﻿using Customer.API.Applcation.Command.SalesCommand;
using Customer.Infrstructre.SalesManager;
using MediatR;

namespace Customer.API.Applcation.CommandHandlers.SalesCommandHandler
{
    public class SalesDelCommandHandler : IRequestHandler<SalesDelCommand, int>
    {

        ISellProductRepository sRep;

        public SalesDelCommandHandler(ISellProductRepository sRep)
        {
            this.sRep = sRep;
        }


        public async Task<int> Handle(SalesDelCommand request, CancellationToken cancellationToken)
        {
            var list = (await sRep.GetAllAsync()).Where(c => request.SellProductId.Contains(c.SellProductId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await sRep.Update(item);
            }
            return 1;
        }
    }
}
